#include "ws2812.h"
#include "tim.h"
#include "main.h"

uint8_t ws2812_init(ws2812_t *handle, uint8_t num, rgb_t *leds,
                    uint8_t (*send)(uint8_t num, rgb_t *leds))
{
    handle->led_num = num;
    handle->leds = leds;
    handle->send = send;
    return 0;
}

uint8_t ws2812_send(ws2812_t *handle)
{
    if (handle->send(handle->led_num, handle->leds))
        return 1;
    return 0;
}


uint8_t ws2812_set_color(ws2812_t *handle, uint8_t index, uint8_t r, uint8_t g, uint8_t b)
{
    if (index >= handle->led_num)
        return 1;
    handle->leds[index].r = r;
    handle->leds[index].g = g;
    handle->leds[index].b = b;
    return 0;
}

uint8_t ws2812_set_color_all(ws2812_t *handle, uint8_t r, uint8_t g, uint8_t b)
{
    for (uint8_t i = 0; i < handle->led_num; i++)
    {
        handle->leds[i].r = r;
        handle->leds[i].g = g;
        handle->leds[i].b = b;
    }
    return 0;
}




